/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{
    public class Danhgia_BaihocDAL : SqlProvider<Danhgia_BaihocEntity>
    {
        static Danhgia_BaihocDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Danhgia_BaihocEntity entity = new Danhgia_BaihocEntity();
                entity.PK_iDanhgia_BaihocID = Int64.Parse("0" + dr["PK_iDanhgia_BaihocID"].ToString());
                entity.FK_iNguoidanhgiaID = Int64.Parse("0" + dr["FK_iNguoidanhgiaID"].ToString());
                entity.FK_iBaihocID = Int64.Parse("0" + dr["FK_iBaihocID"].ToString());
                entity.dThoidiemdanhgia = DateTime.Parse(dr["dThoidiemdanhgia"].ToString());
                return entity;
            };
        }
        public static Danhgia_BaihocEntity GetOne(Int64 PK_iDanhgia_BaihocID)
        {
            string cmdName = "spDanhgia_Baihoc_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDanhgia_BaihocID", PK_iDanhgia_BaihocID);
            Danhgia_BaihocEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Danhgia_BaihocEntity> GetAll()
        {
            string cmdName = "spDanhgia_Baihoc_Get";
            return GetList(cmdName);
        }
        
        public static int Add(Danhgia_BaihocEntity entity)
        {
            string cmdName = "spDanhgia_Baihoc_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Danhgia_BaihocEntity entity)
        {
            string cmdName = "spDanhgia_Baihoc_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iDanhgia_BaihocID)
        {
            string cmdName = "spDanhgia_Baihoc_Delete";
            SqlParameter p = new SqlParameter("@PK_iDanhgia_BaihocID", PK_iDanhgia_BaihocID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Danhgia_BaihocEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iDanhgia_BaihocID", entity.PK_iDanhgia_BaihocID);
			p[1] = new SqlParameter("@FK_iNguoidanhgiaID", entity.FK_iNguoidanhgiaID);
			p[2] = new SqlParameter("@FK_iBaihocID", entity.FK_iBaihocID);
			p[3] = new SqlParameter("@dThoidiemdanhgia", entity.dThoidiemdanhgia);
            return p;
        }
        #endregion
       
    }
}